<?php

namespace App\Http\Controllers;

use App\Http\Model\SystemConfigModel;
use Illuminate\Support\Facades\Cache;

abstract class Controller
{
    //

    public function __construct() {
        $this->cacheSystemConfig();
    }

    public function cacheSystemConfig()
    {
        return Cache::rememberForever('system_config_cache', function () {
            $defaultData = SystemConfigModel::all();
            $cache = [];
            foreach ($defaultData as $value) {
                if (!isset($cache[$value->ltsc003])){
                    $cache[$value->ltsc003] = [];
                    $cache[$value->ltsc003]["children"] = [];
                    $cache[$value->ltsc003]["title"] = $value->ltsc004;
                }
                $cache[$value->ltsc003]["children"][$value->code] = $value;
            }
            return $cache;
        });
    }
}
